﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace WinLogicUniversity.DBBroker
{
    class AfterDeliveryBroker
    {        

        public AfterDeliveryBroker()
        {
           LogicUniversityT2Entities entity = new LogicUniversityT2Entities();
        }

        public static string DepartmentId
        { get; set; }

        public AfterDeliveryBroker(string i)
        {
            DepartmentId = i;
        }

        public static IQueryable getDepartmentReqList()
        {

            LogicUniversityT2Entities entity = new LogicUniversityT2Entities();
            DateTime dt = Convert.ToDateTime(entity.DepartmentRequisitions.Max(g => g.AllocatedDate));
            var Deplist = from DepReq in entity.DepartmentRequisitions
                          join ilist in entity.Items on DepReq.ItemID equals ilist.ItemID
                          where DepReq.DepartmentID == DepartmentId && DepReq.AllocatedDate == dt && DepReq.RequestedQuantity != DepReq.AfterDeliveredQuantity
                          select new
                          {
                              Item_No = DepReq.ItemID,
                              Description = ilist.ItemDescription,
                              Requested_Quantity = DepReq.RequestedQuantity,
                              Delivered_Qty = DepReq.AfterDeliveredQuantity,
                              DepReqID = DepReq.DeptRequisitionID,
                              DepID = DepReq.DepartmentID,
                              AllocatedQty = DepReq.AllocatedQuantity,

                          };
            return Deplist;

        }
        #region AutoGen


        public static string AutoGenAdjVouID()
        {
            LogicUniversityT2Entities entity = new LogicUniversityT2Entities();
            int intId = 0; string AdjID;
            try
            {
                intId = Convert.ToInt32(entity.AdjustmentVouchers.Max(g => g.AdjustmentID).Substring(2));
            }
            catch (NullReferenceException)
            {
                AdjID = "AV00001";
                return AdjID;
            }
            finally
            {
                int MaxAdjID = Convert.ToInt32(intId) + 1;
                AdjID = string.Format("AV{0:00000}", MaxAdjID);
            }
            return AdjID;
        }


        #endregion

    }
}
